package com.konsung.ksdc.manager.addr;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.konsung.ksdc.R;
import com.konsung.ksdc.bean.AddrAdvanceBean;
import com.konsung.ksdc.bean.AddrBaseBean;
import com.konsung.ksdc.common.utils.ActivityCollector;
import com.konsung.ksdc.common.utils.Constants;
import com.konsung.ksdc.common.utils.PreferenceUtils;
import com.konsung.ksdc.manager.appmain.BaseActivity;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2016/5/16 0016.
 */
public class DistrictStep3 extends BaseActivity {

    @Bind(R.id.rl_back)
    RelativeLayout rlBack;
    @Bind(R.id.tab_tv_title)
    TextView tabTvTitle;
    @Bind(R.id.tv_save)
    TextView tvSave;
    @Bind(R.id.rl_title_container)
    RelativeLayout rlTitleContainer;
    @Bind(R.id.lv_area)
    ListView lvArea;
    private AddrAdvanceBean datas;
    private String cityName;
    private String cityCode;

    @Override
    protected String activityDesc() {
        return getString(R.string.page_choose_district);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_district_step);
        ButterKnife.bind(this);
        ActivityCollector.addActivity(DistrictStep3.this);
        initData();
        initView();
    }

    /**
     * init view
     */
    private void initView() {
        lvArea.setAdapter(new DistrictCountyAdapter(this, datas.getAearList()
                , cityName));
        rlBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ActivityCollector.removeActivity(DistrictStep3.this);
                finish();
            }
        });
        lvArea.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int
                    position, long id) {
                AddrBaseBean bean = datas.getAearList().get(position);

                String districtName = cityName + "&" + bean.getAreaName();
                String districtCode = cityCode + "&" + bean.getAreaId();
                PreferenceUtils.putString(DistrictStep3.this,
                        Constants.KEY_DISTRICT_NAME, districtName);
                PreferenceUtils.putString(DistrictStep3.this,
                        Constants.KEY_DISTRICT_CODE, districtCode);
                CreateAddrActivity.haveDistrict = true; //修改标志位,已经有地区数据了
                ActivityCollector.finishAll();
            }
        });

    }


    /**
     * init data
     */
    private void initData() {
        datas = getIntent().getParcelableExtra(DistrictStep2.COUNTY_DATA);
        cityName = getIntent().getStringExtra(DistrictStep2.CITY_NAME);
        cityCode = getIntent().getStringExtra(DistrictStep2.CITY_CODE);
    }


}
